﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using CoreMobile.cmd;
using VABMobile.oo;

namespace VABMobile.cmd
{

    class LoginCommand : SendCommand
    {
        public static string CMD = "login";
        
        protected override void init()
        {
            this.token = LoginCommand.CMD;
            
        }

        public override string[] parameters()
        {
            return new [] { ((Persona)parameter).Rut };
                    
        }

    }

    class TurnoIniCommand : SendCommand
    {
        public static string CMD = "VStartServiceCmd";

        protected override void init()
        {
            this.token = TurnoIniCommand.CMD;
        }

        public override string[] parameters()
        {
            var turno = (Turno) parameter;

            return new string[]{turno.Id
                ,turno.Bus.Patente
                ,turno.Chofer1.Rut
                ,turno.Auxiliar.Rut
                ,turno.Itinerario.Origen
                ,turno.Itinerario.Destino
                ,(turno.Chofer2 == null ? "" : turno.Chofer2.Rut)};
        }

    }

    class TurnoFinCommand : SendCommand
    {
        public static string CMD = "VEndServiceCmd";
        protected override void init()
        {
            this.token = TurnoFinCommand.CMD;
        }

        //#region Overrides of SendCommand

        public override string[] parameters()
        {
            return new[]{((Turno)parameter).Id };
        }

        //#endregion
    }

    class TurnoDatosCommand : ReceiveCommand
    {
        //turno-datos, $id_turno, $patente_bus, $rut_chofer1, $rut_chofer2, $origen, $destino
        public static string CMD = "turno-datos";

        public TurnoDatosCommand(string[] parameters) : base(parameters)
        {
        }
        public TurnoDatosCommand()
            : base()
        {
        }

        protected override void init()
        {
            this.token = TurnoDatosCommand.CMD;
        }

        public override IParameter fromParameterLine(string[] parameters)
        {
            return new Turno(parameters[1]
                      , new Bus(parameters[2])
                ,new Persona(parameters[3]) //chofer2
                ,new Persona(parameters[4]) //chofer1
                ,null //aux
                , new Itinerario(parameters[5]));
        }
    }    

    class AsientoCommand : ReceiveCommand
    {
        public static string CMD = "asiento";

        public AsientoCommand(string[] parameters) : base(parameters)
        {
        }
        public AsientoCommand() : base()
        {
        }

        protected override void init()
        {
            this.token = AsientoCommand.CMD;
        }

        public override IParameter fromParameterLine(string[] parameters)
        {
            //Boleto b=
            return new Asiento(Int32.Parse( parameters[1]))
                .setBoletoEmitido(parameters[2]=="1"?new Boleto():null);
        }
    }

    class RegistroCommand : SendCommand
    {
        //registro, $id_turno, $numero_asiento,  $rut_pasajero ;
        public static string CMD = "VPassangerRegisterCmd";
        protected override void init()
        {
            this.token = RegistroCommand.CMD;
        }

        public override string[] parameters()
        {
            Boleto boleto = (Boleto) parameter;
            return new string[]{boleto.Turno.Id
                   ,""+boleto.Asiento.Numero
                   ,boleto.Pasajero.Rut};
        }

    }

    class VABCommand : SendCommand
    {
        //vab, $id_turno, $numero_asiento, $rut_pasajero, $telefono, $valorCancelado ;
        public static string CMD = "VABOperationCmd";

        protected override void init()
        {
            this.token = VABCommand.CMD;
        }

        public override string[] parameters()
        {
            var boleto = (Boleto) parameter;
            return  new string[]{boleto.Turno.Id
                   ,""+boleto.Asiento.Numero
                   ,boleto.Pasajero.Rut
                   ,boleto.Pasajero.Telefono
                   ,""+boleto.Monto
                   ,boleto.Agencia
                   ,boleto.Destino};
        }
    }
}
